﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Job.Web.Framework;
using System.Collections;
using System.Data.SqlClient;
using Job.Logic.BaseContent;
using System.Data;
using Job.Entity;

namespace Job.Web.userControls.Admin
{
    public partial class LogoManangerList : BaseCtrl
    {
        private int controlType
        {
            get { return myR["controlType"].IntValue; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.BindCount();
                this.BindData();
            }
        }


        private void BindCount()
        {
            //this.winPager1.CurrentPage = 1;
            //AspNetPagerInit.InitPager(pagerButtom);
            DataSet ds = this.GetData(1);
            int count = 0;
            if (ds != null)
            {
                count = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            }
            pagerButtom.RecordCount = count;
            pagerButtom.DataBind();
        }

        void BindData()
        {
            DataSet ds = GetData(0);
            if (ds != null)
            {
                this.gvList.DataSource = ds.Tables[0];
                this.gvList.DataBind();
            }
        }



        private DataSet GetData(int type)
        {
            ArrayList param = new ArrayList();

            //if (controlType >= 0)
            //{
            //    SqlParameter pm = new SqlParameter();
            //    pm.ParameterName = "subject_id";
            //    pm.Value = controlType;
            //    pm.SqlDbType = SqlDbType.Int;
            //    param.Add(pm);
            //}

            BaseContentLogic blogic = new BaseContentLogic();

            DataSet ds = blogic.GetAdvanceCustomerList(pagerButtom.PageSize, pagerButtom.CurrentPageIndex, type, this.SortField, this.SortDirection, param);
            return ds;
        }

        /// <summary>
        /// 排序字段
        /// </summary>
        public Job.Web.Framework.SortDirection SortDirection
        {
            get
            {
                return Job.Web.Framework.SortDirection.Ascending;
            }
        }

        public string SortField
        {
            get
            {
                return "order_no";
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Label lblid = (Label)e.Row.FindControl("lblid");
                HyperLink hlDetail = (HyperLink)e.Row.FindControl("hlDetail");

                //hlDetail.NavigateUrl = "~/AdminWeb/AdminMain.aspx?controlType=113&infoType=0&isEdit=1&contentId="+lblContentId.Text.Trim();
                hlDetail.NavigateUrl = "~/AdminWeb/AdminMain.aspx?controlType="
                    + Convert.ToString(Constants.GetInfoIdByListId(controlType))
                    + "&advid=" + lblid.Text.Trim();

            }
        }

        protected void pagerButtom_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/AdminWeb/AdminMain.aspx?controlType="
    + Convert.ToString(Constants.GetInfoIdByListId(controlType)));
        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            BaseContentLogic blogic = new BaseContentLogic();
            foreach (GridViewRow row in gvList.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    Label lblid = (Label)row.FindControl("lblid");
                    CheckBox chkaction = (CheckBox)row.FindControl("chkone");
                    if (chkaction != null && chkaction.Checked && lblid != null)
                    {
                        int id = Convert.ToInt32(lblid.Text.Trim());
                        blogic.DeleteAdv(id);

                    }
                }
            }
            this.Response.Redirect(this.Request.RawUrl);
        }
    }
}